using System;

namespace Codeflows
{
    public class DisposableContext<T> : IDisposable
    {
        protected Action<T> DisposeAction { get; set; }
        public T Instance { get; set; }
       
        public DisposableContext(T instance) : this(instance, null)
        {
        } 

        public DisposableContext(T instance, Action<T> disposeAction)
        {
            DisposeAction = disposeAction;
            Instance = instance;
        }

        public virtual void Dispose()
        {
            if (DisposeAction != null)
                DisposeAction(Instance);
        }
    }
}